package java_class_work.socketDemo;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * @Author Tiam
 * @Date 2022/11/9 17:05
 * @Description:
 */
public class Client {
    public static void main(String[] args) {
        Socket socket = null;
        try {
            socket = new Socket("localhost", 8888);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(socket);
        // 开启读消息线程, 使其可一直读取服务端的消息
        new Thread(new ClientThread(socket)).start();


        Scanner scanner = new Scanner(System.in);
        PrintWriter pw = null;
        try {
            pw = new PrintWriter(socket.getOutputStream(),true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        while (true){
            System.out.print("请输入:");
            String message = scanner.nextLine();
            pw.println(message);
        }

    }
}
